// loader
const webpack = require('webpack')
const { devMiddleware, hotMiddleware } = require('koa-webpack-middleware')
const devConfig = require('../../webpack.config.js')
const koaStatic = require('koa-static')


module.exports =  (options) => {
  const ENV = options.env,
        app = options.app;
  if (ENV) {
    const compile = webpack(devConfig)
    app.use(devMiddleware(compile, {
        noInfo: true,
        quiet: false,
        lazy: true,
        watchOptions: {
            aggregateTimeout: 300,
            poll: true
        },
        publicPath: "/dist/",
        headers: { "X-Custom-Header": "yes" },
        stats: {
            colors: true
        }
    }))
  } else {
    app.use(koaStatic('/dist'))
  }
}
